package com.smartstate.EMS.entity;

import com.baomidou.mybatisplus.annotation.FieldFill;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;

import javax.persistence.*;
import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * <p>Title: EntityBase</p>
 * <p>Description: </p>
 * <p>Company: www.sh-smartstate.com</p>
 * <p>create date: 2022/03/01</p>
 *
 * @author :Zhou Hang
 * @version :1.0.0
 */
@Data
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
@EnableJpaAuditing
public class EntityBase {

    /**
     * 主键
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @TableId(type = IdType.AUTO)
    @ApiModelProperty(value = "id")
    protected Integer id;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(updatable = false,columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
    @ApiModelProperty(value = "创建时间")
    protected Date createTime;

    /**
     * 修改时间
     */
    @LastModifiedDate
    @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")
    @ApiModelProperty(value = "修改时间")
    protected Date updateTime;

    /**
     * 创建人
     */
    @Column(updatable = false)
    @CreatedBy
    @ApiModelProperty(value = "创建人")
    protected Integer creatorId;

    /**
     * 修改人
     */
    @ApiModelProperty(value = "修改人")
    @Column(insertable = false)
    @LastModifiedBy
    protected Integer updaterId;

    /**
     * 用于后续saas服务租户字段
     */
    @ApiModelProperty(value = "企业编号")
    protected String enterpriseId;

    /**
     * 删除标记
     */
    @ApiModelProperty(value = "删除标记")
    protected boolean deleteMark = false;

    public String getCreateTime() {
        SimpleDateFormat sdf =  new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        return createTime!=null?sdf.format(createTime):null;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public String getUpdateTime() {
        SimpleDateFormat sdf =  new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
        return updateTime!=null?sdf.format(updateTime):null;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }
}
